package priv.stones.reflect;

/**
 * @Author: Stones
 * @Description:
 * @Date: 2017/9/26 10:05
 */

interface Anamal {

    void Shout();

}

class Cat implements Anamal {

    @Override
    public void Shout() {
        System.out.println("喵喵喵~");

    }

}

class Dog implements Anamal {

    @Override
    public void Shout() {
        System.out.println("汪汪汪~");

    }
}


class Tiger implements Anamal {

    @Override
    public void Shout() {
        System.out.println("吼吼吼~");
    }
}



class Factory {

    public static Anamal GetAnamal(String cls) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        return (Anamal) Class.forName(cls).newInstance();
//        if (category.equals("cat")) {
//            return new Cat();
//        } else if (category.equals("dog")) {
//            return new Dog();
//        }
//        else {
//            return new Dog();
//        }
    }

}




public class Reflect3 {

    public static void main(String[] args) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
        Anamal anamal = Factory.GetAnamal("priv.stones.reflect.Tiger");
        anamal.Shout();
    }

}
